package mvc.command.character
{
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.adobe.cairngorm.control.CairngormEventDispatcher;

	import mvc.control.ArmoryEvent;
	import mvc.control.CharacterEvent;

	import mx.containers.TabNavigator;
	import mx.events.FlexEvent;

	import orm.fantasy.TblCharacterVO;

	import view.design.DesignCharacter;

	public class NewDesignCharacterCmd extends CharacterCmd implements ICommand
	{
		public function execute(event:CairngormEvent):void
		{
			var tabCharacters:TabNavigator = super._dsnCharacters.tabCharacters;
			var tblCharacterVO:TblCharacterVO = (event as CharacterEvent).tblCharacterVO;

			var dsnCharacter:DesignCharacter = new DesignCharacter();
			dsnCharacter.tblCharacterVO = tblCharacterVO;

			var index:int = tabCharacters.numChildren - 1;
			tabCharacters.addChildAt(dsnCharacter, index);
			tabCharacters.selectedIndex = index;

			var nextMvcEvent:ArmoryEvent = new ArmoryEvent(ArmoryEvent.EQUIP_ALL_SLOTS, tblCharacterVO);
			nextMvcEvent.data = {dsnCharacter: dsnCharacter};
			CairngormEventDispatcher.getInstance().dispatchEvent(nextMvcEvent);
		}
	}
}